﻿using lingopen.IdStrategy;
using lingopen.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Chloe;
using lingopen.AutoMapper;
using lingopen.Entity.System;

namespace lingopen.Application.System.Implements
{
    public class ServiceAppService : AdminAppService, IServiceAppService
    {


        public PagedData<Sys_Service> GetServices(Pagination pagination, string keyword)
        {
            var q = this.DbContext.Query<Sys_Service>().FilterDeleted().WhereIfNotNullOrEmpty(keyword, a => a.Name.Contains(keyword) || a.EnCode.Contains(keyword));
            q = q.OrderBy(a => a.CreationTime);
            PagedData<Sys_Service> ret = q.TakePageData(pagination);
            return ret;
        }
        public bool UpdateZipPath(string enCode, string path, string filename, long size)
        {
            try
            {
                this.DbContext.DoWithTransaction(() =>
                {
                    this.DbContext.Update<Sys_Service>(a => a.EnCode == enCode, a => new Sys_Service() { ZipPath = path, ZipName = filename, ZipSize = size });

                });
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
    }
}